package service

import (
	"fmt"
	"os"
	"os/exec"

	"k8s.io/client-go/util/homedir"
)

func HelmPackageApps(app string) error {
	path := homedir.HomeDir() + "/tmp/apps/" + app
	fmt.Println(path)
	os.Chdir(path)
	cmd := exec.Command("helm", "package", "package")
	err := cmd.Run()

	if err != nil {
		// 命令执行失败
		panic(err)
	}
	return nil
}

func HelmInstallApps(app string) error {
	path := homedir.HomeDir() + "/tmp/apps/" + app
	fmt.Println(path)
	os.Chdir(path)
	cmd := exec.Command("helm",
		"install", app, app+"-0.1.0.tgz")
	//// 执行命令，返回命令是否执行成功
	//helm install learn-api learn-api-0.1.0.tgz
	err := cmd.Run()

	if err != nil {
		// 命令执行失败
		panic(err)
	}
	return nil
}
